package com.speech.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.speech.R;
import com.speech.item.PropertyRankingItem;

import java.util.List;

public class PropertyRankingAdapter extends BaseAdapter {

    private List<PropertyRankingItem> mLstItem;
    private Context mContext;

    public PropertyRankingAdapter(List<PropertyRankingItem> mLstItem, Context mContext) {
        this.mLstItem = mLstItem;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return mLstItem.size();
    }

    @Override
    public Object getItem(int position) {
        return mLstItem.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if(convertView==null) {
            LayoutInflater inflater = LayoutInflater.from(mContext);
            convertView = inflater.inflate(R.layout.item_ranking, null);
            viewHolder = new ViewHolder();

            viewHolder.sdv_head = convertView.findViewById(R.id.sdv_item_ranking_head);
            viewHolder.img_serial = convertView.findViewById(R.id.img_item_ranking_icon);

            viewHolder.tv_nickname = convertView.findViewById(R.id.tv_item_ranking_nickname);
            viewHolder.tv_invite_num = convertView.findViewById(R.id.tv_item_ranking_invite_num);
            viewHolder.tv_property = convertView.findViewById(R.id.tv_item_ranking_property);

            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        PropertyRankingItem item = mLstItem.get(position);

        viewHolder.img_serial.setImageResource(item.iResIconID);
        viewHolder.sdv_head.setImageURI(Uri.parse(item.strHeadUrl));
        viewHolder.tv_property.setText(item.strProperty);
        viewHolder.tv_nickname.setText(item.strNickName);
        viewHolder.tv_invite_num.setText(item.strInviteNum);

        return convertView;
    }

    class ViewHolder{
        ImageView img_serial;
//        ImageView img_head;
        SimpleDraweeView sdv_head;

        TextView tv_nickname;
        TextView tv_invite_num;
        TextView tv_property;
    }
}
